// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';
// 申明请求对象
const ipqcRequst = {
    BASE_URL: confing.QC_URL + "/ipqc",
    //新增请求

    //多选删除按钮
    deletes(ipqcIds, callback) {
        //拼接URL
        let url = this.BASE_URL + "/deletes?t=1";
        if (ipqcIds != undefined) {
            ipqcIds.forEach(ipqcId => {
                url += "&ipqcId=" + ipqcId;
            })
            request.delete(url, callback);
        }
    },
    //删除信息
    delete(ipqcId, callback) {
        request.delete(this.BASE_URL + "/" + ipqcId, callback);
    },
    //编辑信息
    edit(ipqc, callback) {
        if (ipqc != undefined && ipqc.ipqcId != undefined) {
            request.put(this.BASE_URL + "/update", ipqc, callback);
        }

    },

    //根据id查询信息
    get(ipqcId, callback) {
        if (ipqcId) {
            // 准备url
            let url = this.BASE_URL + "/get?ipqcId=" + ipqcId;
            request.get(url, callback);
        }

    },
    //保存信息
    save(ipqc, callback) {
        if (ipqc) {
            request.post(this.BASE_URL + "/save", ipqc, callback);
        }
    },
    // 请求的API
    list(page = 1, limit = 10, ipqc, callbcak) {
        // url
        let url = this.BASE_URL + "/list?page=" + page +
            "&limit=" + limit;
        if (ipqc) {
            if (ipqc.iqcCode) {
                url += "&iqcCode=" + ipqc.iqcCode;
            }
            if (ipqc.vendorName) {
                url += "&vendorName=" + ipqc.vendorName;
            }
            if (ipqc.vendorBatch) {
                url += "&vendorBatch=" + ipqc.vendorBatch;
            }
            if (ipqc.itemCode) {
                url += "&itemCode=" + ipqc.itemCode;
            }
            if (ipqc.itemName) {
                url += "&itemName=" + ipqc.itemName;
            }
            if (ipqc.checkResult) {
                url += "&checkResult=" + ipqc.checkResult;
            }
            if (ipqc.reciveDate) {
                url += "&reciveDate=" + ipqc.reciveDate;
            }
            if (ipqc.inspectDate) {
                url += "&inspectDate=" + ipqc.inspectDate;
            }
            if (ipqc.inspecor) {
                url += "&inspecor=" + ipqc.inspecor;
            }

        }
        // 发送请求
        request.get(url, callbcak);
    }

}

// 将dictRequest暴漏出去
export default ipqcRequst;